//
//  HJOfficialController.m
//  KaiChat
//
//  Created by lx on 2023/12/21.
//

#import "HJOfficialController.h"
#import "HJFriendListHeaderView.h"
#import "HJIM.h"
#import "HJSupportController.h"

@interface HJOfficialController ()

@property (nonatomic, strong) NSArray *datas;

@end

@implementation HJOfficialController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationBar.title = @"About Kai";
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:HJFriendListHeaderCell.class forCellReuseIdentifier:@"HJFriendListHeaderCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 60;
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(KNavBarHight);
        make.left.right.bottom.offset(0);
    }];
    [self loadData];
}

- (void)loadData {
    [HJIM.shareIM.chatManager loadOfficialAccountCompletion:^(NSArray * _Nullable datas) {
        self.datas = datas;
        [self.tableView reloadData];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HJFriendListHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HJFriendListHeaderCell" forIndexPath:indexPath];
    cell.sessionModel = self.datas[indexPath.row];;
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    HJChatSessionModel *sessionModel = self.datas[indexPath.row];
    if (sessionModel.officialType == HJChatOfficialTypeKaiNews) {
        [self.navigationController pushViewControllerWithName:@"HJNewsController"];
        return;
    }
    
    if (sessionModel.officialType == HJChatOfficialTypeKaiSupport) {
        HJSupportController *supportController = [[HJSupportController alloc] init];
        supportController.sessionModel = sessionModel;
        [self.navigationController pushViewController:supportController];
        return;
    }
    
    if (sessionModel.officialType == HJChatOfficialTypeKaiPay) {
        [self.navigationController pushViewControllerWithName:@"HJPayBillController"];
        return;
    }
    
}
 
 
@end

 
